package com.runshu.newsmartark.base;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;

import com.runshu.newsmartark.smartbox.SmartBoxHelper;
import com.runshu.newsmartark.smartbox.SmartBoxListener;

import java.util.HashMap;
import java.util.List;


/**
 * @author yu
 * @date 2020/11/9
 * @decs：
 */
public abstract class TakeStockBase extends BaseActivity implements SmartBoxListener {
    public Context context;

    protected void onCreate(Bundle savedInstanceState) {
        context = this;
        Log.e( "box", "smartboxlistener" );
        super.onCreate( savedInstanceState );
        if ( BoxBaseActivity.ctx!=null){
            BoxBaseActivity.ctx.addBoxListener( this );
        }
    }

    @Override
    public void onScanResult(List<HashMap<String, String>> data, boolean fromCloseDoor) {
//        SmartBoxHelper.getInstance().stopScan( this, 0 );
    }

    private boolean bTmpInventoryFlag = true;

    @Override
    public void onOpenDoor() {

    }

    @Override
    public void onCloseDoor() {
        Log.e( "box", "takestockbase_startscan" );
        startScan();
//        SmartBoxHelper.getInstance().startScan( this );
    }

    public void startScan() {
        SmartBoxHelper.getInstance().startScan( this );
    }

    //关门
    public void closeDoor(int delay) {
        SmartBoxHelper.getInstance().closeDoor( this, delay );
    }

    private Handler mHandler = new Handler();
    private Runnable mRefreshRunnable = new Runnable() {
        public void run() {
            //refreshList();
            mHandler.postDelayed( this, 2000 );
        }
    };

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
       BoxBaseActivity.ctx.unRegisterBoxListener( this );
    }
}